﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Main_Inventory_InventoryPrint_StockJournalDisplayDetails : System.Web.UI.Page
{
    string Category = "";
    string TFOID = "";
    string SJRID = "";
    string FormatName = "";
    string FormatNo = "";
    string Date = "";
    Datautility DU = new Datautility();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Category"] != null && Request.QueryString["TFOID"] != null && Request.QueryString["SJRID"] != null)
        {
            Category = Request.QueryString["Category"].ToString();
            TFOID=Request.QueryString["TFOID"].ToString();
            SJRID = Request.QueryString["SJRID"].ToString();
            FormatName = Request.QueryString["FormatName"].ToString();
            FormatNo = Request.QueryString["FormatNo"].ToString();
            Date = Request.QueryString["Date"].ToString(); 
        }
        if (!IsPostBack)
        {
            BindCategoryPanel(Category);
        }
    }
    protected void BindCategoryPanel(string CategoryID)
    {
        if (CategoryID == "1")  // Journal (Input Output)
        {
            pnljournal.Visible = true;
            BindJournal();

            pnlproduction.Visible = false;
            pnlissue.Visible = false;
            pnlreceipt.Visible = false;
            pnltransfer.Visible = false;
            pnlphysical.Visible = false;
        }
       else if (CategoryID == "2") // Production
        {
            pnlproduction.Visible = true;

            BindProduction();

            pnljournal.Visible = false;
            pnlissue.Visible = false;
            pnlreceipt.Visible = false;
            pnltransfer.Visible = false;
            pnlphysical.Visible = false;
        }
        else if (CategoryID == "3")  // Issue
        {
            pnlissue.Visible = true;

            BindIssue();

            pnljournal.Visible = false;
            pnlproduction.Visible = false;
            pnlreceipt.Visible = false;
            pnltransfer.Visible = false;
            pnlphysical.Visible = false;
        } 
        else if (CategoryID == "4")   // Reciept
        {
            pnlreceipt.Visible = true;

            BindReceipt();

            pnljournal.Visible = false;
            pnlproduction.Visible = false;
            pnlissue.Visible = false;
            pnltransfer.Visible = false;
            pnlphysical.Visible = false;
        }
        else if (CategoryID == "5")  // Transfer
        {
            pnltransfer.Visible = true;

            BindTransfer();

            pnljournal.Visible = false;
            pnlproduction.Visible = false;
            pnlissue.Visible = false;
            pnlreceipt.Visible = false;
            pnlphysical.Visible = false;
        }
        else if (CategoryID == "6")  // Physical
        {
            pnlphysical.Visible = true;

            BindPhysical();

            pnljournal.Visible = false;
            pnlproduction.Visible = false;
            pnlissue.Visible = false;
            pnlreceipt.Visible = false;
            pnltransfer.Visible = false;
        }
    }

    protected void BindJournal() // Input Output
    {
            lbljournalformat.Text = FormatName.ToString();
            lbljournalno.Text = FormatNo.ToString();
            lbljournaldate.Text = Date.ToString();
            #region InputDataLoad
            
            SqlParameter[] parmainput = { 
                                               new SqlParameter("@SJRID",SJRID),
                                               new SqlParameter("@issue_receipt","Issue") // issue (0) for Input
                                              };

            DataTable dtinput = DU.getdatausingprocedure("usp_ivr_stockJournalDisplay_By_Issue_Receipt", parmainput);
            if (dtinput.Rows.Count > 0)
            {
                for (int i = 0; i < dtinput.Rows.Count; i++)
                {
                    HtmlTableRow row1 = new HtmlTableRow();

                    HtmlTableCell cell1 = new HtmlTableCell();
                    cell1.Align = "Left";
                    cell1.Width = Unit.Percentage(14).ToString();
                    cell1.Style.Add("border-left", "1px solid #818181;");
                    cell1.Style.Add("border-right", "1px solid #818181;");
                    cell1.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinitems = new Label();
                    //lblinitems.Font.Bold = true;
                    lblinitems.Text = dtinput.Rows[i]["Item"].ToString();


                    HtmlTableCell cell2 = new HtmlTableCell();
                    cell2.Align = "Left";
                    cell2.Width = Unit.Percentage(14).ToString();
                    cell2.Style.Add("border-right", "1px solid #818181;");
                    cell2.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinunit = new Label();
                    //lblinunit.Font.Bold = true;
                    lblinunit.Text = dtinput.Rows[i]["unit"].ToString();

                    HtmlTableCell cell3 = new HtmlTableCell();
                    cell3.Align = "Right";
                    cell3.Width = Unit.Percentage(14).ToString();
                    cell3.Style.Add("border-right", "1px solid #818181;");
                    cell3.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinqty = new Label();
                    //lblinqty.Font.Bold = true;
                    lblinqty.Text = dtinput.Rows[i]["itmqty"].ToString();

                    HtmlTableCell cell4 = new HtmlTableCell();
                    cell4.Align = "Right";
                    cell4.Width = Unit.Percentage(14).ToString();
                    cell4.Style.Add("border-right", "1px solid #818181;");
                    cell4.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinrate = new Label();
                    //lblinrate.Font.Bold = true;
                    lblinrate.Text = dtinput.Rows[i]["rate"].ToString();

                    HtmlTableCell cell5 = new HtmlTableCell();
                    cell5.Align = "Right";
                    cell5.Width = Unit.Percentage(14).ToString();
                    cell5.Style.Add("border-right", "1px solid #818181;");
                    cell5.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinamt = new Label();
                    //lblinamt.Font.Bold = true;
                    lblinamt.Text = dtinput.Rows[i]["amount"].ToString();



                    cell1.Controls.Add(lblinitems);
                    cell2.Controls.Add(lblinunit);
                    cell3.Controls.Add(lblinqty);
                    cell4.Controls.Add(lblinrate);
                    cell5.Controls.Add(lblinamt);

                    row1.Cells.Add(cell1);
                    row1.Cells.Add(cell2);
                    row1.Cells.Add(cell3);
                    row1.Cells.Add(cell4);
                    row1.Cells.Add(cell5);

                    tblinput.Rows.Add(row1);
                    
                }
            }

            #endregion

            #region OutputDataLoad

            SqlParameter[] parmaoutput = { 
                                               new SqlParameter("@SJRID",SJRID),
                                               new SqlParameter("@issue_receipt","Receipt") // issue (1) for Output
                                              };

            DataTable dtoutput = DU.getdatausingprocedure("usp_ivr_stockJournalDisplay_By_Issue_Receipt", parmaoutput);
            if (dtoutput.Rows.Count > 0)
            {
                for (int i = 0; i < dtoutput.Rows.Count; i++)
                {
                    HtmlTableRow row1 = new HtmlTableRow();

                    HtmlTableCell cell1 = new HtmlTableCell();
                    cell1.Align = "Left";
                    cell1.Width = Unit.Percentage(14).ToString();
                    cell1.Style.Add("border-left", "1px solid #818181;");
                    cell1.Style.Add("border-right", "1px solid #818181;");
                    cell1.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinitems = new Label();
                    //lblinitems.Font.Bold = true;
                    lblinitems.Text = dtoutput.Rows[i]["Item"].ToString();


                    HtmlTableCell cell2 = new HtmlTableCell();
                    cell2.Align = "Left";
                    cell2.Width = Unit.Percentage(14).ToString();
                    cell2.Style.Add("border-right", "1px solid #818181;");
                    cell2.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinunit = new Label();
                    //lblinunit.Font.Bold = true;
                    lblinunit.Text = dtoutput.Rows[i]["unit"].ToString();

                    HtmlTableCell cell3 = new HtmlTableCell();
                    cell3.Align = "Right";
                    cell3.Width = Unit.Percentage(14).ToString();
                    cell3.Style.Add("border-right", "1px solid #818181;");
                    cell3.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinqty = new Label();
                    //lblinqty.Font.Bold = true;
                    lblinqty.Text = dtoutput.Rows[i]["itmqty"].ToString();

                    HtmlTableCell cell4 = new HtmlTableCell();
                    cell4.Align = "Right";
                    cell4.Width = Unit.Percentage(14).ToString();
                    cell4.Style.Add("border-right", "1px solid #818181;");
                    cell4.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinrate = new Label();
                    //lblinrate.Font.Bold = true;
                    lblinrate.Text = dtoutput.Rows[i]["rate"].ToString();

                    HtmlTableCell cell5 = new HtmlTableCell();
                    cell5.Align = "Right";
                    cell5.Width = Unit.Percentage(14).ToString();
                    cell5.Style.Add("border-right", "1px solid #818181;");
                    cell5.Style.Add("border-bottom", "1px solid #818181;");

                    Label lblinamt = new Label();
                    //lblinamt.Font.Bold = true;
                    lblinamt.Text = dtoutput.Rows[i]["amount"].ToString();



                    cell1.Controls.Add(lblinitems);
                    cell2.Controls.Add(lblinunit);
                    cell3.Controls.Add(lblinqty);
                    cell4.Controls.Add(lblinrate);
                    cell5.Controls.Add(lblinamt);

                    row1.Cells.Add(cell1);
                    row1.Cells.Add(cell2);
                    row1.Cells.Add(cell3);
                    row1.Cells.Add(cell4);
                    row1.Cells.Add(cell5);

                    tbloutput.Rows.Add(row1);

                }
            }

            #endregion

        #region OtherDetails 
            SqlParameter[] paraother = { 
                                        new SqlParameter("@SJRID",SJRID)
                                       };
            DataTable dtother = DU.getdatausingprocedure("usp_ivr_stockJournalDisplayOtherDetails", paraother);
            if (dtother.Rows.Count > 0)
            {
                    lbljournaldetailsnarrations.Text = dtother.Rows[0]["NARRATION"].ToString();
                    lbljournaldetailspreparedby.Text = dtother.Rows[0]["PREPAREDBY"].ToString();
                    lbljournaldetailsremarks.Text = dtother.Rows[0]["REMARKS"].ToString();
                    lbljournaldetailscheckedby.Text = dtother.Rows[0]["CHECKEDBY"].ToString();
                    lbljournaldetailsnote.Text = dtother.Rows[0]["NOTE"].ToString();
                    lbljournaldetailsauthorisedsignatory.Text = dtother.Rows[0]["AUTHRSDSIGNAT"].ToString();
            }
        #endregion 
    }

    protected void BindProduction() // Production
    {
        lblprodformat.Text = FormatName.ToString();
        lblprodjournalno.Text = FormatNo.ToString();
        lblproddate.Text = Date.ToString();

        #region Prod

        SqlParameter[] parmaprod = { 
                                     new SqlParameter("@SJRID",SJRID),
                                     new SqlParameter("@issue_receipt","Receipt")
                                   };
        DataTable dtprod = DU.getdatausingprocedure("usp_ivr_stockJournalDisplay_By_Issue_Receipt",parmaprod);
        if (dtprod.Rows.Count > 0)
        {
            lblproditems.Text = dtprod.Rows[0]["Item"].ToString();
            lblprodunit.Text = dtprod.Rows[0]["Unit"].ToString();
            lblprodqty.Text = dtprod.Rows[0]["Itmqty"].ToString();
            lblprodrate.Text = dtprod.Rows[0]["rate"].ToString();
            lblprodamt.Text = dtprod.Rows[0]["amount"].ToString();
        }

        SqlParameter[] paraproduction = { 
                                          new SqlParameter("@SJRID",SJRID),
                                          new SqlParameter("@issue_receipt","Issue")
                                        };
        DataTable dtproduction = DU.getdatausingprocedure("usp_ivr_stockJournalDisplay_By_Issue_Receipt", paraproduction);
        if (dtproduction.Rows.Count > 0)
        {
            for (int i = 0; i < dtproduction.Rows.Count; i++)
            {
                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Left";
                cell1.Width = Unit.Percentage(14).ToString();
                cell1.Style.Add("border-left", "1px solid #818181;");
                cell1.Style.Add("border-right", "1px solid #818181;");
                cell1.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinitems = new Label();
                //lblinitems.Font.Bold = true;
                lblinitems.Text = dtproduction.Rows[i]["Item"].ToString();


                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Left";
                cell2.Width = Unit.Percentage(14).ToString();
                cell2.Style.Add("border-right", "1px solid #818181;");
                cell2.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinunit = new Label();
                //lblinunit.Font.Bold = true;
                lblinunit.Text = dtproduction.Rows[i]["unit"].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Right";
                cell3.Width = Unit.Percentage(14).ToString();
                cell3.Style.Add("border-right", "1px solid #818181;");
                cell3.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinqty = new Label();
                //lblinqty.Font.Bold = true;
                lblinqty.Text = dtproduction.Rows[i]["itmqty"].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Right";
                cell4.Width = Unit.Percentage(14).ToString();
                cell4.Style.Add("border-right", "1px solid #818181;");
                cell4.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinrate = new Label();
                //lblinrate.Font.Bold = true;
                lblinrate.Text = dtproduction.Rows[i]["rate"].ToString();

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Right";
                cell5.Width = Unit.Percentage(14).ToString();
                cell5.Style.Add("border-right", "1px solid #818181;");
                cell5.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinamt = new Label();
                //lblinamt.Font.Bold = true;
                lblinamt.Text = dtproduction.Rows[i]["amount"].ToString();

                cell1.Controls.Add(lblinitems);
                cell2.Controls.Add(lblinunit);
                cell3.Controls.Add(lblinqty);
                cell4.Controls.Add(lblinrate);
                cell5.Controls.Add(lblinamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                tblproduction.Rows.Add(row1);

            }
        }

        #endregion Prod

        #region Production Items

        #region OtherDetails
        SqlParameter[] paraother = { 
                                        new SqlParameter("@SJRID",SJRID)
                                   };
        DataTable dtother = DU.getdatausingprocedure("usp_ivr_stockJournalDisplayOtherDetails", paraother);
        if (dtother.Rows.Count > 0)
        {
            lblproductiondetailsnarrations.Text = dtother.Rows[0]["NARRATION"].ToString();
            lblproductiondetailspreparedby.Text = dtother.Rows[0]["PREPAREDBY"].ToString();
            lblproductiondetailsremarks.Text = dtother.Rows[0]["REMARKS"].ToString();
            lblproductiondetailscheckedby.Text = dtother.Rows[0]["CHECKEDBY"].ToString();
            lblproductiondetailsnote.Text = dtother.Rows[0]["NOTE"].ToString();
            lblproductiondetailsauthorisedsignatory.Text = dtother.Rows[0]["AUTHRSDSIGNAT"].ToString();
        }
        #endregion 

      #endregion Production Items

    }

    protected void BindIssue()  // Issue
    {
        lblissuefomat.Text = FormatName.ToString();
        lblissueno.Text = FormatNo.ToString();
        lblissuedate.Text = Date.ToString();

        #region Issue Item

        SqlParameter[] paraproduction = { 
                                          new SqlParameter("@SJRID",SJRID),
                                          new SqlParameter("@issue_receipt","All") // Both Issue and Receipt
                                        };
        DataTable dtissue = DU.getdatausingprocedure("usp_ivr_stockJournalDisplay_By_Issue_Receipt", paraproduction);
        if (dtissue.Rows.Count > 0)
        {
            for (int i = 0; i < dtissue.Rows.Count; i++)
            {
                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Left";
                cell1.Width = Unit.Percentage(14).ToString();
                cell1.Style.Add("border-left", "1px solid #818181;");
                cell1.Style.Add("border-right", "1px solid #818181;");
                cell1.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinitems = new Label();
                //lblinitems.Font.Bold = true;
                lblinitems.Text = dtissue.Rows[i]["Item"].ToString();


                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Left";
                cell2.Width = Unit.Percentage(14).ToString();
                cell2.Style.Add("border-right", "1px solid #818181;");
                cell2.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinunit = new Label();
                //lblinunit.Font.Bold = true;
                lblinunit.Text = dtissue.Rows[i]["unit"].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Right";
                cell3.Width = Unit.Percentage(14).ToString();
                cell3.Style.Add("border-right", "1px solid #818181;");
                cell3.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinqty = new Label();
                //lblinqty.Font.Bold = true;
                lblinqty.Text = dtissue.Rows[i]["itmqty"].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Right";
                cell4.Width = Unit.Percentage(14).ToString();
                cell4.Style.Add("border-right", "1px solid #818181;");
                cell4.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinrate = new Label();
                //lblinrate.Font.Bold = true;
                lblinrate.Text = dtissue.Rows[i]["rate"].ToString();

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Right";
                cell5.Width = Unit.Percentage(14).ToString();
                cell5.Style.Add("border-right", "1px solid #818181;");
                cell5.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinamt = new Label();
                //lblinamt.Font.Bold = true;
                lblinamt.Text = dtissue.Rows[i]["amount"].ToString();

                cell1.Controls.Add(lblinitems);
                cell2.Controls.Add(lblinunit);
                cell3.Controls.Add(lblinqty);
                cell4.Controls.Add(lblinrate);
                cell5.Controls.Add(lblinamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                tblissue.Rows.Add(row1);

            }
        }

        #endregion

        #region OtherDetails
        SqlParameter[] paraother = { 
                                        new SqlParameter("@SJRID",SJRID)
                                       };
        DataTable dtother = DU.getdatausingprocedure("usp_ivr_stockJournalDisplayOtherDetails", paraother);
        if (dtother.Rows.Count > 0)
        {
            lblissuedetailsnarrations.Text = dtother.Rows[0]["NARRATION"].ToString();
            lblissuedetailspreparedby.Text = dtother.Rows[0]["PREPAREDBY"].ToString();
            lblissuedetailsremarks.Text = dtother.Rows[0]["REMARKS"].ToString();
            lblissuedetailscheckedby.Text = dtother.Rows[0]["CHECKEDBY"].ToString();
            lblissuedetailsnote.Text = dtother.Rows[0]["NOTE"].ToString();
            lblissuedetailsauthorisedsignatory.Text = dtother.Rows[0]["AUTHRSDSIGNAT"].ToString();
        }
        #endregion 
    }

    protected void BindReceipt()  // Receipt
    {
        lblreceiptformat.Text = FormatName.ToString();
        lblreceiptno.Text = FormatNo.ToString();
        lblreceiptdate.Text = Date.ToString();

        #region Issue Item

        SqlParameter[] paraproduction = { 
                                          new SqlParameter("@SJRID",SJRID),
                                          new SqlParameter("@issue_receipt","All") // Both Issue and Receipt
                                        };
        DataTable dtreceipt = DU.getdatausingprocedure("usp_ivr_stockJournalDisplay_By_Issue_Receipt", paraproduction);
        if (dtreceipt.Rows.Count > 0)
        {
            for (int i = 0; i < dtreceipt.Rows.Count; i++)
            {
                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Left";
                cell1.Width = Unit.Percentage(14).ToString();
                cell1.Style.Add("border-left", "1px solid #818181;");
                cell1.Style.Add("border-right", "1px solid #818181;");
                cell1.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinitems = new Label();
                //lblinitems.Font.Bold = true;
                lblinitems.Text = dtreceipt.Rows[i]["Item"].ToString();


                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Left";
                cell2.Width = Unit.Percentage(14).ToString();
                cell2.Style.Add("border-right", "1px solid #818181;");
                cell2.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinunit = new Label();
                //lblinunit.Font.Bold = true;
                lblinunit.Text = dtreceipt.Rows[i]["unit"].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Right";
                cell3.Width = Unit.Percentage(14).ToString();
                cell3.Style.Add("border-right", "1px solid #818181;");
                cell3.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinqty = new Label();
                //lblinqty.Font.Bold = true;
                lblinqty.Text = dtreceipt.Rows[i]["itmqty"].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Right";
                cell4.Width = Unit.Percentage(14).ToString();
                cell4.Style.Add("border-right", "1px solid #818181;");
                cell4.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinrate = new Label();
                //lblinrate.Font.Bold = true;
                lblinrate.Text = dtreceipt.Rows[i]["rate"].ToString();

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Right";
                cell5.Width = Unit.Percentage(14).ToString();
                cell5.Style.Add("border-right", "1px solid #818181;");
                cell5.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinamt = new Label();
                //lblinamt.Font.Bold = true;
                lblinamt.Text = dtreceipt.Rows[i]["amount"].ToString();

                cell1.Controls.Add(lblinitems);
                cell2.Controls.Add(lblinunit);
                cell3.Controls.Add(lblinqty);
                cell4.Controls.Add(lblinrate);
                cell5.Controls.Add(lblinamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                tblreceipt.Rows.Add(row1);

            }
        }

        #endregion

        #region OtherDetails
        SqlParameter[] paraother = { 
                                        new SqlParameter("@SJRID",SJRID)
                                       };
        DataTable dtother = DU.getdatausingprocedure("usp_ivr_stockJournalDisplayOtherDetails", paraother);
        if (dtother.Rows.Count > 0)
        {
            lblreceiptdetailsnarrations.Text = dtother.Rows[0]["NARRATION"].ToString();
            lblreceiptdetailspreparedby.Text = dtother.Rows[0]["PREPAREDBY"].ToString();
            lblreceiptdetailsremarks.Text = dtother.Rows[0]["REMARKS"].ToString();
            lblreceiptdetailscheckedby.Text = dtother.Rows[0]["CHECKEDBY"].ToString();
            lblreceiptdetailsnote.Text = dtother.Rows[0]["NOTE"].ToString();
            lblreceiptdetailsauthorisedsignatory.Text = dtother.Rows[0]["AUTHRSDSIGNAT"].ToString();
        }
        #endregion
    }

    protected void BindTransfer()  // Transfer
    {
        lbltransferformat.Text = FormatName.ToString();
        lbltransferno.Text = FormatNo.ToString();
        lbltransferdate.Text = Date.ToString();

        #region Issue Item

        SqlParameter[] paratransfer = { 
                                          new SqlParameter("@SJRID",SJRID),
                                          new SqlParameter("@issue_receipt","All") // Both Issue and Receipt
                                        };
        DataTable dttransfer = DU.getdatausingprocedure("usp_ivr_stockJournalDisplay_By_Issue_Receipt", paratransfer);
        if (dttransfer.Rows.Count > 0)
        {
            if (dttransfer.Rows[0]["FromLoaction"] != null && dttransfer.Rows[0]["ToLocation"] != null)
            {
                lblfromlocation.Text = dttransfer.Rows[0]["FromLoaction"].ToString();
                lbltolocation.Text = dttransfer.Rows[0]["ToLocation"].ToString();
            }
            for (int i = 0; i < dttransfer.Rows.Count; i++)
            {
                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Left";
                cell1.Width = Unit.Percentage(14).ToString();
                cell1.Style.Add("border-left", "1px solid #818181;");
                cell1.Style.Add("border-right", "1px solid #818181;");
                cell1.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinitems = new Label();
                //lblinitems.Font.Bold = true;
                lblinitems.Text = dttransfer.Rows[i]["Item"].ToString();


                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Left";
                cell2.Width = Unit.Percentage(14).ToString();
                cell2.Style.Add("border-right", "1px solid #818181;");
                cell2.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinunit = new Label();
                //lblinunit.Font.Bold = true;
                lblinunit.Text = dttransfer.Rows[i]["unit"].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Right";
                cell3.Width = Unit.Percentage(14).ToString();
                cell3.Style.Add("border-right", "1px solid #818181;");
                cell3.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinqty = new Label();
                //lblinqty.Font.Bold = true;
                lblinqty.Text = dttransfer.Rows[i]["itmqty"].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Right";
                cell4.Width = Unit.Percentage(14).ToString();
                cell4.Style.Add("border-right", "1px solid #818181;");
                cell4.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinrate = new Label();
                //lblinrate.Font.Bold = true;
                lblinrate.Text = dttransfer.Rows[i]["rate"].ToString();

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Right";
                cell5.Width = Unit.Percentage(14).ToString();
                cell5.Style.Add("border-right", "1px solid #818181;");
                cell5.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinamt = new Label();
                //lblinamt.Font.Bold = true;
                lblinamt.Text = dttransfer.Rows[i]["amount"].ToString();

                cell1.Controls.Add(lblinitems);
                cell2.Controls.Add(lblinunit);
                cell3.Controls.Add(lblinqty);
                cell4.Controls.Add(lblinrate);
                cell5.Controls.Add(lblinamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                tbl_transfer.Rows.Add(row1);

            }
        }

        #endregion

        #region OtherDetails
        SqlParameter[] paraother = { 
                                        new SqlParameter("@SJRID",SJRID)
                                       };
        DataTable dtother = DU.getdatausingprocedure("usp_ivr_stockJournalDisplayOtherDetails", paraother);
        if (dtother.Rows.Count > 0)
        {
            lbltransferdetailsnarrations.Text = dtother.Rows[0]["NARRATION"].ToString();
            lbltransferdetailspreparedby.Text = dtother.Rows[0]["PREPAREDBY"].ToString();
            lbltransferdetailsremarks.Text = dtother.Rows[0]["REMARKS"].ToString();
            lbltransferdetailscheckedby.Text = dtother.Rows[0]["CHECKEDBY"].ToString();
            lbltransferdetailsnote.Text = dtother.Rows[0]["NOTE"].ToString();
            lbltransferdetailsauthorisedsignatory.Text = dtother.Rows[0]["AUTHRSDSIGNAT"].ToString();
        }
        #endregion
    }

    protected void BindPhysical()  // Physical
    {
        lblphysicalformat.Text = FormatName.ToString();
        lblphysicalno.Text = FormatNo.ToString();
        lblphysicaldate.Text = Date.ToString();

        #region Issue Item

        SqlParameter[] paratransfer = { 
                                          new SqlParameter("@SJRID",SJRID),
                                          new SqlParameter("@issue_receipt","All") // Both Issue and Receipt
                                        };
        DataTable dtphysical = DU.getdatausingprocedure("usp_ivr_stockJournalDisplay_By_Issue_Receipt", paratransfer);
        if (dtphysical.Rows.Count > 0)
        {
            for (int i = 0; i < dtphysical.Rows.Count; i++)
            {
                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Left";
                cell1.Width = Unit.Percentage(14).ToString();
                cell1.Style.Add("border-left", "1px solid #818181;");
                cell1.Style.Add("border-right", "1px solid #818181;");
                cell1.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinitems = new Label();
                //lblinitems.Font.Bold = true;
                lblinitems.Text = dtphysical.Rows[i]["Item"].ToString();


                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Left";
                cell2.Width = Unit.Percentage(14).ToString();
                cell2.Style.Add("border-right", "1px solid #818181;");
                cell2.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinunit = new Label();
                //lblinunit.Font.Bold = true;
                lblinunit.Text = dtphysical.Rows[i]["unit"].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Right";
                cell3.Width = Unit.Percentage(14).ToString();
                cell3.Style.Add("border-right", "1px solid #818181;");
                cell3.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinqty = new Label();
                //lblinqty.Font.Bold = true;
                lblinqty.Text = dtphysical.Rows[i]["itmqty"].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Right";
                cell4.Width = Unit.Percentage(14).ToString();
                cell4.Style.Add("border-right", "1px solid #818181;");
                cell4.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinrate = new Label();
                //lblinrate.Font.Bold = true;
                lblinrate.Text = dtphysical.Rows[i]["rate"].ToString();

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Right";
                cell5.Width = Unit.Percentage(14).ToString();
                cell5.Style.Add("border-right", "1px solid #818181;");
                cell5.Style.Add("border-bottom", "1px solid #818181;");

                Label lblinamt = new Label();
                //lblinamt.Font.Bold = true;
                lblinamt.Text = dtphysical.Rows[i]["amount"].ToString();

                HtmlTableCell cell6 = new HtmlTableCell();
                cell6.Align = "Left";
                cell6.Width = Unit.Percentage(14).ToString();
                cell6.Style.Add("border-right", "1px solid #818181;");
                cell6.Style.Add("border-bottom", "1px solid #818181;");

                Label lblphresion = new Label();
                //lblinamt.Font.Bold = true;
                lblphresion.Text = dtphysical.Rows[i]["reason"].ToString();

                cell1.Controls.Add(lblinitems);
                cell2.Controls.Add(lblinunit);
                cell3.Controls.Add(lblinqty);
                cell4.Controls.Add(lblinrate);
                cell5.Controls.Add(lblinamt);
                cell6.Controls.Add(lblphresion);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);
                row1.Cells.Add(cell6);

                tbl_physical.Rows.Add(row1);

            }
        }

        #endregion

        #region OtherDetails
        SqlParameter[] paraother = { 
                                        new SqlParameter("@SJRID",SJRID)
                                       };
        DataTable dtother = DU.getdatausingprocedure("usp_ivr_stockJournalDisplayOtherDetails", paraother);
        if (dtother.Rows.Count > 0)
        {
            lblphysicaldetailsnarrations.Text = dtother.Rows[0]["NARRATION"].ToString();
            lblphysicaldetailspreparedby.Text = dtother.Rows[0]["PREPAREDBY"].ToString();
            lblphysicaldetailsremarks.Text = dtother.Rows[0]["REMARKS"].ToString();
            lblphysicaldetailscheckedby.Text = dtother.Rows[0]["CHECKEDBY"].ToString();
            lblphysicaldetailsnote.Text = dtother.Rows[0]["NOTE"].ToString();
            lblphysicaldetailsauthorisedsignatory.Text = dtother.Rows[0]["AUTHRSDSIGNAT"].ToString();
        }
        #endregion
    }
}
